package com.tanhua.manager.listener;

import com.tanhua.manager.domain.Log;
import com.tanhua.manager.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
@RocketMQMessageListener(topic = "tanhua-log", consumerGroup = "tanhua-log-consumer")
public class LogMessageListener implements RocketMQListener<Map> {

    @Autowired
    private LogService logService;
    @Override
    public void onMessage(Map message) {
        log.info("【接收MQ消息】topic:{}, message:{}", "tanhua-log", message);
        //调用service存入tb_log
        Long userId = Long.parseLong(message.get("userId").toString());
        String type = (String) message.get("type");
        String date = (String) message.get("date");

        Log logObj = new Log();
        logObj.setUserId(userId);
        logObj.setLogTime(date);
        logObj.setType(type);
//        logObj.setCreated(new Date());
//        logObj.setUpdated(new Date());
        logService.save(logObj);
    }
}
